/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.PlanoDaoLocal;
import entities.Plano;
import exception.PlanoExistsException;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

/**
 *
* @author Sostenes, Thiago, Felipe
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class PlanoController implements PlanoControllerLocal {

    @EJB
    private PlanoDaoLocal planoDao;

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void persist(Plano plano) throws PlanoExistsException {
        if (planoDao.exists(plano)) {
            throw new PlanoExistsException(plano);
        }
        planoDao.create(plano);
    }

    @Override
    public Plano createPlano() {
        return new Plano();
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void remove(Plano plano) {
        planoDao.remove(plano);
    }

    @Override
    @TransactionAttribute()
    public List<Plano> list() {
        return planoDao.list();
    }
}
